﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Simple : System.Web.UI.Page
{
    public Data.VarParams varParam = new Data.VarParams();
    public Data.Data currentData = new Data.Data();
    public Data.DataConsolidation dc = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        String errMsg = varParam.ReadFile( Request.PhysicalApplicationPath, this.Session.SessionID );
        if (errMsg == null)
        {
            dc = new Data.DataConsolidation(varParam);

            String projectFileName = "";
            Boolean error = ExecuteProjectFile( projectFileName );
            if (error == false)
            {
                // we have the data in the currentData object. Now we can do anything with it.
            }
        }
    }
    Boolean ExecuteProjectFile( String projectFileName )
    {
        String fullProjectFileName = varParam.GetMyProjectsDir() + projectFileName;
        if ( System.IO.File.Exists(fullProjectFileName))
        {
            String [] projectItems = System.IO.File.ReadAllLines( fullProjectFileName );

            foreach( String projectItem in projectItems )
            {
                Boolean initialLoad = true;
                Boolean success = dc.RunScript(projectItem, currentData, initialLoad);
                if (success == false)
                    return success;
            }
            return false;
        }
        return false;
    }
}
